﻿<%@ WebHandler Language="C#" Class="check_user" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using Tools;
using Newtonsoft.Json;
public class check_user : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {

        string validateCode = string.Empty,
                userUame = string.Empty,
                userPwd = string.Empty,
                result = string.Empty,
                jsonData = string.Empty;

        Dictionary<string, object> resultItem = null;

        validateCode = string.Format("{0}", context.Request["validateCode"]);

        if (validateCode.Equals(context.Session["valicode"]))
        {
            result = "2";

            userUame = string.Format("{0}", context.Request["userName"]);

            userPwd = string.Format("{0}", context.Request["userPwd"]);
            //防止SQL注入
            string sql = @"select * from t_employee
                                where emp_password = @emp_password and emp_name = @emp_name";

            SqlParameter[] pars = new SqlParameter[] {
                new SqlParameter("@emp_name",userUame),
                new SqlParameter("@emp_password",Biz.GetMD5Str(userPwd))
            };

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnection(), System.Data.CommandType.Text, sql,pars))
            {
                if (reader.Read())
                {
                    result = "1";

                    resultItem = new Dictionary<string, object>();

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        resultItem.Add(reader.GetName(i), reader[i]);
                    }
                }
            }
        }
        else
        {
            result = "-1";
        }

        var obj = new
        {
            status = result,
            item = resultItem
        };

        context.Response.ContentType = "text/plain";
        context.Response.Write(JsonConvert.SerializeObject(obj));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}